﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using System.ComponentModel;
using TA.DotNetUtils;
using System.ComponentModel.Design;
using System.Drawing.Design;
using TA.Turbo.Controls;
using TA.Win.Utils.Design;

namespace TA.Turbo
{
	/// <summary>
	/// Provides a set of properties that can be set to control how a control's state is transferred over the network during a request.
	/// </summary>
	public class ControlTransferOptions : BaseSpecialControlNoId, ICloneable
	{
		#region PUBLIC
		#region PROPS
		/// <summary>
		/// Send the value if true, do not if false.
		/// </summary>
		[DefaultValue(true)]
		public bool Value { get; set; }
		/// <summary>
		/// List of comma-separated properties to be included or excluded, depending on the PropertiesMode, from the request. (connected to PropertiesList)
		/// </summary>		
		[DefaultValue("")]
		public virtual string Properties { get { return _mpv.Value; } set { _mpv.Value = value; } }
		/// <summary>
		/// List of properties to be included or excluded, depending on the PropertiesMode, from the request. (connected to Properties)
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[Editor(typeof(StringCollectionEditor<DefaultStringOptionsProvider>), typeof(UITypeEditor))]
		public virtual List<string> PropertiesList { get { return _mpv.ValueList; } }
		/// <summary>
		/// Changes the meaning of Properties and PropertiesList.
		/// </summary>
		[DefaultValue(InclusionMode.OnlyIncluded)]
		public InclusionMode PropertiesMode { get; set; }
		/// <summary>
		/// Returns true is anything needs to be sent for this control (either value or any properties or both); otherwise, false.
		/// </summary>
		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public bool Anything
		{
			get
			{

				return Value || AnyProperties;
			}
		}
		/// <summary>
		/// Gets true if any properties need to be sent for this control.
		/// </summary>
		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public bool AnyProperties
		{
			get
			{
				return (
							PropertiesMode == InclusionMode.OnlyIncluded
							&&
							PropertiesList.Count > 0
						)
						||
						(
							PropertiesMode == InclusionMode.AllExceptExcluded
						);
			}
		}
		#endregion
		#region METHODS
		/// <summary>
		/// Creates and returns a clone of this object.
		/// </summary>
		/// <returns></returns>
		public object Clone()
		{
			ControlReference r = (ControlReference)MemberwiseClone();
			//r._propertiesList = null;
			return r;
		}
		#endregion
		#endregion
		#region INTERNAL
		#region VARS
		MultiPartValue _mpv = new MultiPartValue();
		#endregion
		#region RENDER
		#endregion
		#endregion
	}


}
